import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/widgets/my_app_bar.dart';
import 'package:nft_shop/widgets/status_view.dart';
import 'package:webview_flutter/webview_flutter.dart';

class WebsiteDel extends StatefulWidget {
  String webUrl;
  String title;

  WebsiteDel(this.title, this.webUrl, {Key? key}) : super(key: key);

  @override
  _WebsiteDelState createState() => _WebsiteDelState();
}

class _WebsiteDelState extends State<WebsiteDel> {
  late int status = LoadStatusType.loading;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: MyAppBar(
          centerTitle: widget.title,
        ),
        body: getWidget());
  }

  getWidget() {
    // if (status != LoadStatusType.success) {
    //   return ;
    // }
    return Stack(
      children: [
        WebView(
          onWebResourceError: (WebResourceError error) {
            setState(() {
              status = LoadStatusType.empty;
            });
          },
          onPageFinished: (String url) {
            setState(() {
              status = LoadStatusType.success;
            });
          },
          onProgress: (int progress) {
            debugPrint("");
          },
          onWebViewCreated: (WebViewController controller) {
            debugPrint("");
          },
          initialUrl: widget.webUrl,
          javascriptMode: JavascriptMode.unrestricted,
        ),
        Visibility(
            visible: status != LoadStatusType.success,
            child: Container(
              alignment: Alignment.topCenter,
              color: Colors.white,
              width: double.infinity,
              height: Get.height,
              child: StatusViews(status),
            ))
      ],
    );
  }
}
